package com.dl7.mvp.module.video.list;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;

import com.dl7.mvp.R;
import com.dl7.mvp.adapter.SlideInBottomAdapter;
import com.dl7.mvp.injector.components.DaggerAlbumsListComponent;
import com.dl7.mvp.injector.modules.AlbumsListModule;
import com.dl7.mvp.local.table.AlbumsListBean;
import com.dl7.mvp.module.base.BaseFragment;
import com.dl7.mvp.module.base.IBasePresenter;
import com.dl7.mvp.module.base.ILoadDataView;
import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.helper.RecyclerViewHelper;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

public class AlbumsListFragment extends BaseFragment<IBasePresenter> implements ILoadDataView<List<AlbumsListBean.DataBean.AlbumsBean>> {

    private static final String CATEGORY_ID = "category_id";

    @BindView(R.id.rv_recommend_video_list)
    RecyclerView mRvVideoList;

    @Inject
    BaseQuickAdapter mAdapter;
    private int mID;

    public static AlbumsListFragment newInstance(int id) {
        AlbumsListFragment fragment = new AlbumsListFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(CATEGORY_ID, id);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mID = getArguments().getInt(CATEGORY_ID);
        }
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.fragment_category_video_list;
    }

    @Override
    protected void initInjector() {
        DaggerAlbumsListComponent.builder()
                .applicationComponent(getAppComponent())
                .albumsListModule(new AlbumsListModule(this, mID))
                .build()
                .inject(this);
    }

    @Override
    protected void initViews() {
        SlideInBottomAdapter slideAdapter = new SlideInBottomAdapter(mAdapter);
        RecyclerViewHelper.initRecyclerViewV(mContext, mRvVideoList, slideAdapter);
    }

    @Override
    protected void updateViews() {
        mPresenter.getData();
    }


    @Override
    public void loadData(List<AlbumsListBean.DataBean.AlbumsBean> videoList) {
        mAdapter.updateItems(videoList);
        hideLoading();
    }

    @Override
    public void loadMoreData(List<AlbumsListBean.DataBean.AlbumsBean> videoList) {
    }

    @Override
    public void loadNoData() {
        mAdapter.loadAbnormal();
    }
}
